﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using LockCrypt.Core;

namespace LockCrypt {
    public class Field : FieldBase, INotifyPropertyChanged {
        public override string Name {
            get { return base.Name; }
            set {
                base.Name = value;
                OnPropertyChanged("Name");
            }
        }
        public override string Value {
            get { return base.Value; }
            set {
                base.Value = value;
                OnPropertyChanged("Value");
            }
        }
        public override FieldMetaData Meta {
            get { return base.Meta; }
            set {
                base.Meta = value;
                OnPropertyChanged("Meta");
            }
        }
        public override int SortIndex {
            get { return base.SortIndex; }
            set {
                base.SortIndex = value;
                OnPropertyChanged("SortIndex");
            }
        }

        /// <summary>
        /// Initializes a <see cref="Field"/>.
        /// </summary>
        public Field()
            : base() {
        }

        /// <summary>
        /// Initializes a <see cref="Field"/> from another field.
        /// </summary>
        /// <param name="field">The base field.</param>
        public Field(IField field)
            : this() {
            this.Meta = field.Meta;
            this.Name = field.Name;
            this.SortIndex = field.SortIndex;
            this.Value = field.Value;
        }

        /// <summary>
        /// Creates a deep copy of this field.
        /// </summary>
        /// <returns>A clone of this field.</returns>
        public override IField Clone() {
            FieldBase clone = new FieldBase() {
                Name = this.Name,
                Value = this.Value,
                Meta = this.Meta,
                SortIndex = this.SortIndex
            };
            return clone;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string strPropertyName) {
            if(PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(strPropertyName));
            }
        }
    }
}
